package com.chw.admin.scheduling;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chw.utils.CommonFieldsUtil;
import com.chw.utils.UUIDUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class ChwSchedulingService implements IChwSchedulingService {

	@Autowired
	private ChwSchedulingMapper chwSchedulingeMapper;

	// 新增
	@Override
	public int addEntity(ChwScheduling entity) {
		try {
			String id = UUIDUtil.getUUID();
			entity.setId(id);
			CommonFieldsUtil.setCreateValueByCy(entity);
			this.chwSchedulingeMapper.insert(entity);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	// 修改
	@Override
	public int updateEntity(ChwScheduling entity) {
		try {
			// 更新头
			// entity.setLastUpdatedDate(new Date());
			// entity.setEnabledFlag("Y");
			CommonFieldsUtil.setUpdateValue(entity);
			// this.chwStorageMapper.updateByPrimaryKey(entity);
			this.chwSchedulingeMapper.updateByPrimaryKeySelective(entity);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	// 逻辑删除头
	@Override
	public int deleteEntity(String id) {
		try {
			this.chwSchedulingeMapper.deleteById(id);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	// 查询 id
	@Override
	public ChwScheduling getEntityById(String id) {
		return this.chwSchedulingeMapper.selectByPrimaryKey(id);
	}

	// 分页查询
	@Override
	public PageInfo<ChwScheduling> findEntity(ChwScheduling entity, Integer currentPage, Integer pageSize) {
		PageHelper.startPage(currentPage.intValue(), pageSize.intValue());
		List<ChwScheduling> list = this.chwSchedulingeMapper.findByEntity(entity);
		return new PageInfo(list);
	}
}